package pl.smath.parser.text;

import junit.framework.TestCase;


public class TokenizerTestCase extends TestCase {

	/** 
	 * Test data for parser. 
	 */
	private static final String[][] testData = {
		{"+ -", "+", "-"},
		{" 2 + 3 ", "2", "+", "3"},
		{"2.2 + 3.6 ", "2.2", "+", "3.6"},
		{"2.2 + a", "2.2", "+", "a"},
		{"2.2*a + (3.6+b)^x ", "2.2", "*", "a", "+", "(", "3.6", "+", "b", ")", "^", "x", }
	};
	
	public void testData() {
		
		Tokenizer 	tokenizer;
		Token		token;
		
		
		for(int i = 0; i < testData.length; i++){

			tokenizer = new Tokenizer( testData[i][0] );

			for(int j=1; j < testData[i].length; j++){
				
				token = tokenizer.nextToken();
				assertEquals(testData[i][0], testData[i][j], token.getText());
			}
		}
	}
	
	public void testPushback() {
		
		Tokenizer 	tokenizer;
		Token		token;
		
		
		tokenizer = new Tokenizer( "2+3" );

		token = tokenizer.nextToken();
		assertEquals("2", token.getText());

		tokenizer.pushback(token);
		token = tokenizer.nextToken();
		assertEquals("2", token.getText());
		
		token = tokenizer.nextToken();
		assertEquals("+", token.getText());
		
		token = tokenizer.nextToken();
		assertEquals("3", token.getText());

		tokenizer.pushback(token);
		assertEquals(true, tokenizer.hasMoreTokens());
		token = tokenizer.nextToken();
		assertEquals("3", token.getText());
		
	}
	
}
